package com.zoro.dyformservice.utils;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class Base64Util {

    public static String encoding(String source) {
        if (source == null || source.length() == 0) {
            return null;
        }
        byte[] result = Base64.getEncoder().encode(source.getBytes(StandardCharsets.UTF_8));
        return new String(result);
    }

    public static String decoding(String source) {
        if (source == null || source.length() == 0) {
            return null;
        }
        byte[] result = Base64.getDecoder().decode(source.getBytes(StandardCharsets.UTF_8));
        return new String(result);
    }

    public static String urlEncoding(String source) {
        if (source == null || source.length() == 0) {
            return null;
        }

        byte[] result = Base64.getUrlEncoder().encode(source.getBytes(StandardCharsets.UTF_8));
        return new String(result);
    }

    public static String urlDecoding(String source) {
        if (source == null || source.length() == 0) {
            return null;
        }
        byte[] result = Base64.getUrlDecoder().decode(source.getBytes(StandardCharsets.UTF_8));
        return new String(result);
    }
}
